package com.flyweight.factory;

import com.flyweight.iface.Shape;
import com.flyweight.po.Square;

import java.util.HashMap;
import java.util.Map;

public class ShapeFactory {

    public static final Map<String, Shape> shapeMap = new HashMap<>();

    public static Shape getSquare(String color) {
        Square square = (Square) shapeMap.get(color);

        if ( square == null ) {
            System.out.println("[INFO] new color '" + color + "' shape was built in shape factory.");
            square = new Square(color);
            shapeMap.put(color, square);
        }

        return square;
    }

}
